package com.mes.defece.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mes.common.pojo.MESResult;
import com.mes.defece.mapper.TestingTemplateMapper;
import com.mes.defece.service.TestingTemplateService;
import com.mes.pojo.defece.TestingTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 侯伟豪
 * @Company 起点编程
 * @Description
 * @Time 2024/10/18 17:01
 */
@Service
public class TestingTemplateServiceImpl implements TestingTemplateService {
    @Autowired
    private TestingTemplateMapper testingTemplateMapper;
    @Override
    public MESResult selectAll(TestingTemplate testingTemplate, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<TestingTemplate> testingTemplates = testingTemplateMapper.selectAll(testingTemplate);
        return MESResult.success(new PageInfo<>(testingTemplates));
    }

    @Override
    public MESResult addTestingTemplate(TestingTemplate testingTemplate) {
        if (testingTemplate.getTestingTemplateStatus() == null){
            testingTemplate.setTestingTemplateStatus(1);
        }
        List<Integer> testingProjectList = testingTemplate.getTestingProjectList();
        System.out.println(testingProjectList.get(0));
        testingTemplate.setTestingTemplateType(testingProjectList.get(0));
        return MESResult.success(testingTemplateMapper.insertTestingTemplate(testingTemplate));
    }

    @Override
    public MESResult selectById(Long testingTemplateId) {
        return MESResult.success(testingTemplateMapper.selectById(testingTemplateId));
    }

    @Override
    public MESResult updateTestingTemplateById(TestingTemplate testingTemplate) {
        return MESResult.success(testingTemplateMapper.updateTestingTemplateById(testingTemplate));
    }

    @Override
    public MESResult deleteTestingTemplate(Long testingTemplateId, Integer testingTemplateStatus) {
        TestingTemplate testingTemplate = new TestingTemplate();
        testingTemplate.setTestingTemplateId(testingTemplateId);
        testingTemplate.setTestingTemplateStatus(99);
        return MESResult.success(testingTemplateMapper.deleteTestingTemplateById(testingTemplate));
    }

}